one = int(input("Введите четырёхзначное натуральное число: ")) 
if not 1000 <= one <= 9999: 
    print(0) 
else: 
    max_prime = 0 
    one_str = str(one) 
    for i in range(4, 0, -1):   
        for j in range(0, 5 - i): 
            sub_one = int(one_str[j:j+i]) 
            if sub_one > 1: 
                is_prime = True 
                for k in range(2, int(sub_one**0.5) + 1): 
                    if sub_one % k == 0: 
                        is_prime = False 
                        break 
                if is_prime and sub_one > max_prime: 
                    max_prime = sub_one 
    print(max_prime if max_prime else 0)
